package com.chinasofti.demo03;

public class Demo03 {
    public static void main(String[] args) throws InterruptedException {
        Object obj = new Object();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("2."+Thread.currentThread().getState());
                synchronized (obj) {
                    try {
                        Thread.sleep(100);
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("4."+Thread.currentThread().getState());
            }
        });
        System.out.println("1."+thread.getState());
        thread.start();
        thread.sleep(150);
        System.out.println("3."+thread.getState());
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj){
                    obj.notify();
                }
            }
        }).start();
        thread.sleep(150);
        System.out.println("5."+thread.getState());
    }
}
